package edu.ustb.Controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

import edu.ustb.service.GoodsService;
import edu.ustb.service.GoodsServiceImpl;
@SuppressWarnings("serial")
@MultipartConfig
@WebServlet("/admin/goods/save.do")
public class GoodsSaveController extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String goodsName = request.getParameter("goodsName");
		String goodsPrice = request.getParameter("goodsPrice");
		String goodsNum = request.getParameter("goodsNum");
		String goodsDetail = request.getParameter("goodsDetail");
		Part part = request.getPart("goodsImg");
		String savePath = request.getServletContext().getRealPath("/uploadimg");
		
		GoodsService goodsSaveService=new  GoodsServiceImpl();
		goodsSaveService.save(goodsName, goodsPrice, goodsNum, goodsDetail, part, savePath);
	    request.getRequestDispatcher("/admin/goods/search.action").forward(request, response);
	}
}
